package com.example.textview.listview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.textview.R;

import java.text.SimpleDateFormat;
import java.util.Date;

public class MylistAdapter extends BaseAdapter {

    private Context context;//可以理解为一个容器
    private LayoutInflater layoutInflater;
   public MylistAdapter(Context context)
    {
       this. context=context;
       this.layoutInflater=LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return 10;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    static  class ViewHolder{
       public ImageView imageView;
       public TextView tvTitle,tvTime,tvContent;
    }
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
       ViewHolder holder=null;
       if(view==null)
       {
           view=layoutInflater.inflate(R.layout.layout_list_item,null);
           holder=new ViewHolder();
           holder.imageView=(ImageView) view.findViewById(R.id.iv);
           holder.tvTitle=view.findViewById(R.id.tv_title);
           holder.tvTime=view.findViewById(R.id.tv_time);
           holder.tvContent=view.findViewById(R.id.tv_content);
           view.setTag(holder);

       }

       else {

           holder= (ViewHolder) view.getTag();
       }

        String str = String.valueOf ( i );

        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");// HH:mm:ss
        Date date=new Date(System.currentTimeMillis());

        holder.tvTitle.setText(str);
        holder.tvTime.setText(simpleDateFormat.format(date));
        //holder.tvTime.setText("2020-06-00");
        holder.tvContent.setText("这是内容");
        //https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1593502249697&di=f51d9232bea665f63783da0ac7601f0a&imgtype=0&src=http%3A%2F%2Fe.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2Ff31fbe096b63f624a76a76948644ebf81a4ca376.jpg
        Glide.with(context).load("http://app1.showapi.com/weather/icon/day/07.png").into(holder.imageView);
        return view;
    }
}
